//
//  PostCommon_Config.h
//  PostDelivery
//
//  Created by wmz on 2020/6/18.
//  Copyright © 2020 wmz. All rights reserved.
//

#ifndef PostCommon_Config_h
#define PostCommon_Config_h

#define PostHeight [UIScreen mainScreen].bounds.size.height
#define PostWidth  [UIScreen mainScreen].bounds.size.width
#define PostNavigationBar (([[UIApplication sharedApplication] statusBarFrame].size.height) + 44)
#define PostNavigationStatusBar (([[UIApplication sharedApplication] statusBarFrame].size.height))
#define PostNum(with)   (floor((with) * (kWidthCoefficientTo6S)))
#define kWidthCoefficientTo6S PostWidth / 375.0
#define PostColorP(rgbValue,alpah) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alpah]
#define PostColor(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define PostK1px (1 / UIScreen.mainScreen.scale)
#define PostTabBarHeight (PostIsIphoneX ? (49.f+34.f) : 49.f)
#define PostBottomSafeHeight (CGFloat)(PostIsIphoneX?(34.0):(0))

#define PostIsIphoneX ({\
BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
if ([[[UIApplication sharedApplication] delegate] window].safeAreaInsets.bottom > 0.0) {\
isPhoneX = YES;\
}\
}\
isPhoneX;\
})

#ifndef HDWeakify
    #if DEBUG
        #if __has_feature(objc_arc)
            #define HDWeakify(obj) autoreleasepool{} __weak __typeof__(obj) obj##Weak = obj;
        #else
            #define HDWeakify(obj) autoreleasepool{} __block __typeof__(obj) obj##Block = obj;
        #endif
    #else
        #if __has_feature(objc_arc)
            #define HDWeakify(obj) try{} @finally{} {} __weak __typeof__(obj) obj##Weak = obj;
        #else
            #define HDWeakify(obj) try{} @finally{} {} __block __typeof__(obj) obj##Block = obj;
        #endif
    #endif
#endif

#ifndef HDStrongify
    #if DEBUG
        #if __has_feature(objc_arc)
            #define HDStrongify(obj) autoreleasepool{} __typeof__(obj) obj = obj##Weak;
        #else
            #define HDStrongify(obj) autoreleasepool{} __typeof__(obj) obj = obj##Block;
        #endif
    #else
        #if __has_feature(objc_arc)
            #define HDStrongify(obj) try{} @finally{} __typeof__(obj) obj = obj##Weak;
        #else
            #define HDStrongify(obj) try{} @finally{} __typeof__(obj) obj = obj##Block;
        #endif
    #endif
#endif

#define PostUserGet(key)  [[NSUserDefaults standardUserDefaults]objectForKey:key]
#define PostUserSet(object,key)  [[NSUserDefaults standardUserDefaults] setObject:object forKey:key];
#define PostUserDefault [NSUserDefaults standardUserDefaults]

// 字符串为空
#ifndef GNStringNotEmpty
#define GNStringNotEmpty(__string) (__string != nil && ([__string isKindOfClass:NSString.class]) && (__string.length))
#endif

// 字符串设置不为空
#ifndef GNFillEmpty
#define GNFillEmpty(__string) (__string != nil ? __string : @"")
#endif

// 字符串设置不为空
#ifndef GNFillEmptySpace
#define GNFillEmptySpace(__string) (__string != nil ? __string : @" ")
#endif

// 字符串设置不为空 金额为分
#ifndef GNFillMonEmpty
#define GNFillMonEmpty(__string) (__string != nil ? [NSString stringWithFormat:@"￥%0.2f", [[__string decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithString:@"100"]] doubleValue]] : @" ")
#endif

///金额为元
#ifndef GNFillNormalMonEmpty
#define GNFillNormalMonEmpty(__string) (__string != nil ? [NSString stringWithFormat:@"%0.2f", [__string doubleValue]] : @"0")
#endif


/// 文件前缀
#define GNFillImage(image)  (image != nil ? [NSString stringWithFormat:@"%@%@",[BSNetAPIClient realURLWithKey:@"imageURL"],image] : nil)

/// html文本适应字体
#define GNHTMLFill(content)  [@"<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'><style>img{max-width:100%}</style></header>" stringByAppendingString:content?:@""]

#endif /* PostCommon_Config_h */
